/************************************************************
 * Copyright (C), 2022-2030, dina. Co., Ltd.
 * FileName:        i_can.h
 * Author:          Dan Yin
 * Date:            2023-05-12
 * Description:     the class of CAN interface
 * Version:         1.0.0.0
 **********************************************************/

#ifndef I_CAN_H
#define I_CAN_H

// add necessary includes here
#include <QObject>

#define ICan_iid "org.qt-project.Qt.Examples.ICan"

typedef struct ST_CAN_FRAME {
    unsigned int nFrameId;
    QByteArray baFrameData;
}CAN_FRAME;


// define a pure virtual class
class ICan : public QObject
{
    Q_OBJECT
public:
    // open a CAN bus
    virtual int openCAN() = 0;

    // close a CAN bus
    virtual void closeCAN() = 0;

    // send an frame data to CAN bus
    virtual int sendFrameData(ST_CAN_FRAME stCanFrame, bool bQueued) = 0;

signals:
    int signalSendFrameData(ST_CAN_FRAME stCanFrame, bool bQueued);

    // Receive a payload packet from serialbus
    void signalPayloadReceived(unsigned int nCanId, QByteArray baPayload);
};

// declare interface
Q_DECLARE_INTERFACE(ICan, ICan_iid)

Q_DECLARE_METATYPE(ST_CAN_FRAME);

#endif // I_CAN_H
